<template>
  <!-- 顶部京东注册 -->
  <van-sticky>
    <van-nav-bar title="京东注册" left-text="返回" left-arrow @click-left="$router.go(-1)" />
  </van-sticky>


  <van-form @submit="onSubmit" style="margin-top:70px">
    <van-cell-group inset>
      <!-- 通过 pattern 进行正则校验 -->
      <van-field v-model="password" type="password" name="pattern" label="密码" placeholder="至少6位,包含:数字,大写字母,小写字母"
        :rules="[{ pattern, message: '密码不符合规范,请重新填写' }]" />
    </van-cell-group>
    <div style="margin: 36px 16px">
      <van-button round block native-type="submit" v-if="!pattern.test(password)"
        style="background-color:#FA7B7B;color:white">
        完成
      </van-button>
      <van-button round block native-type="submit" v-else style="background-color:red;color:white">
        完成
      </van-button>
    </div>
  </van-form>
</template>

<script>
import { dofinishregister } from '../server/regist.js'
import { showDialog } from 'vant';
export default {
  data() {
    return {
      password: "",
      showBtn: false,
      pattern: /(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,30}/  //密码正则
    }
  },

  methods: {
    onSubmit() {
      // 将手机号存储到仓库
      localStorage.setItem("password", this.password)
      // this.$store.commit("passwordStore", this.password)
      
      // 获取手机号
      let password = localStorage.getItem("password")
      let tel = localStorage.getItem("telphone")
      // let tel = this.$store.state.telphone
      // let password = this.$store.state.password

      dofinishregister({ password, tel }).then((res) => {
        showDialog({
          message: '注册成功',
        }).then(() => {
          this.$router.push("/login")
        });
      })
    }
  }
}

</script>
<style scoped>

</style>